<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="ch">
  
  <head>
    <base th:href="${#request.getScheme()}+'://'+${#request.getServerName()}+':'+${#request.getServerPort()}+${#request.getContextPath()}">
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网站用户</title>
    <link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}"/>
    <script th:inline="javascript">
      var basePath = [[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]];
    </script>
<!--    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />-->
      <script th:src="@{/layui/layui.js}"></script>
    <link rel="stylesheet" href="../../xadmin/css/font.css">
    <link rel="stylesheet" href="../../xadmin/css/xadmin.css">
      <script th:src="@{/layui/jquery.min.js}"></script>
<!--    <script type="text/javascript" src="../../xadmin/lib/layui/layui.js" charset="utf-8"></script>-->
    <script type="text/javascript" src="../../xadmin/js/xadmin.js"></script>

  </head>
  
  <body style="margin:10px;background-color: white">
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" lay-filter="searchForm">

          <div class="layui-input-inline">
            <select name="contrller">
              <option value="">订单状态</option>
              <option value="0">已取消</option>
              <option value="1">未付款</option>
              <option value="2">待发货</option>
              <option value="3">已发货</option>
              <option value="4">已完成</option>
            </select>
          </div>
          <input type="text" name="username" id="orderNumber" placeholder="请输入订单号" autocomplete="off" class="layui-input">
          <button class="layui-btn"  lay-submit="" lay-filter="sreach" id="searchbyorder"><i class="layui-icon">&#xe615;</i></button>
            <button class="layui-btn"  data-type="reload"  id="searchAll">查看所有</button>
        </form>
      </div>
<!--      <xblock>-->
<!--        <button class="layui-btn layui-btn-normal" onclick="delever()" >批量发货</button>-->

<!--      </xblock>-->
        <!--自定义toolbar-->
        <script type="text/html" id="toolbarDemo">
            <button class="layui-btn layui-btn-normal"  lay-event="deleverMore">批量发货</button>
        </script>
      <table class="layui-table" id="demo" lay-filter="test">
<!--        <thead>-->
<!--          <tr>-->
<!--            <th>-->
<!--              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>-->
<!--            </th>-->
<!--            <th>订单编号</th>-->
<!--            <th>收货人</th>-->
<!--            <th>总金额</th>-->
<!--            <th>应付金额</th>-->
<!--            <th>订单状态</th>-->
<!--            <th>支付状态</th>-->
<!--            <th>发货状态</th>-->
<!--            <th>支付方式</th>-->
<!--            <th>配送方式</th>-->
<!--            <th>下单时间</th>-->
<!--            <th >操作</th>-->
<!--            </tr>-->
<!--        </thead>-->
<!--        <tbody>-->
<!--          <tr>-->
<!--            <td>-->
<!--              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>-->
<!--            </td>-->
<!--            <td>2017009171822298053</td>-->
<!--            <td>老王:18925139194</td>-->
<!--            <td>7829.10</td>-->
<!--            <td>7854.10</td>-->
<!--            <td>待确认</td>-->
<!--            <td>未支付</td>-->
<!--            <td>未发货</td>-->
<!--            <td>其他方式</td>-->
<!--            <td>申通物流</td>-->
<!--            <td>2017-08-17 18:22</td>-->
<!--            <td class="td-manage">-->
<!--              <a title="查看"  onclick="x_admin_show('编辑','order-view.html')" href="javascript:;">-->
<!--                <i class="layui-icon">&#xe63c;</i>-->
<!--              </a>-->
<!--              <a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">-->
<!--                <i class="layui-icon">&#xe640;</i>-->
<!--              </a>-->
<!--            </td>-->
<!--          </tr>-->
<!--        </tbody>-->
      </table>

        <script type="text/html" id="user-tbl-toolbar">
            <a class="layui-btn layui-btn-xs" lay-event="orderDetail">详情</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="delever">发货</a>
        </script>

<!--        //订单详情模态框-->
        <div id="orderDetail-layer" style="display: none; padding: 20px">
            <form id="orderDetail-form" class="layui-form layui-form-pane" lay-filter="orderDetail-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">订单号</label>
                    <div class="layui-input-block">
                        <input type="text" name="orderId" class="layui-input" lay-verify="required" autocomplete="off" disabled="true" readonly="true">
<!--                        <input type="text" name="orderId" th:if="${session.orderAndItem!=null ? '不断啊' :'气死了'}"  class="layui-input" lay-verify="required" autocomplete="off" >-->
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">收货人</label>
                    <div class="layui-input-block">
                        <input type="text" name="receiverName" class="layui-input" lay-verify="required" autocomplete="off" disabled="true" readonly="true">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">总金额</label>
                    <div class="layui-input-block">
                        <input type="text" name="totalPrice" class="layui-input" lay-verify="required" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">收货人电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="receiverPhone" class="layui-input" lay-verify="required" autocomplete="off" readonly="true">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="update-user-form-submit">确定</button>
                    </div>
                </div>
            </form>
        </div>

    </div>
    <script th:inline="none">

        // layui.use('laydate', function(){
      layui.use(['table','layer','element', 'jquery', 'form','laydate'], function() {
          var laydate = layui.laydate;
          var $ = layui.$, table = layui.table, layer = layui.layer, form = layui.form;

          table.render({
              toolbar: '#toolbarDemo',
              elem: '#demo'
              , url: '/admin/getAllOrderslist' //数据接口
              , page: true //开启分页
              , cols: [[
                  {type: 'checkbox', fixed: 'left'}
                  , {field: 'orderId', title: '订单号', width: 180, sort: true, fixed: 'left'}
                  , {field: 'receiverName', title: '收货人', width: 180}
                  , {field: 'totalPrice', title: '总金额', width: 180}
                  , {field: 'receiverPhone', title: '收货人电话', width: 180}
                  , {field: 'status', title: '订单状态', width: 180}
                  // ,{field: 'createTime', title: '创建时间',width:160, templet : function(value){return layui.util.toDateString(value.createTime);}
                  ,{field: 'createTimeStr', title: '创建时间',width:160}
                  //   ,{field: 'createTime', title: '创建时间',width:160, templet:"<div>{{layui.util.toDateString(data.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                  // }
                  , {title: '操作', toolbar: '#user-tbl-toolbar'}
              ]]
              //0(用户取消订单);1(未付款);2(已付款);3(已发货);4(交易完成);
              , done: function (res, curr, count) {
                  $("[data-field='status']").children().each(function () {
                      if ($(this).text() == 0) {
                          $(this).text("已取消")
                      } else if ($(this).text() == 1) {
                          $(this).text("未付款")
                      } else if ($(this).text() == 2) {
                          $(this).text("待发货")
                      } else if ($(this).text() == 3) {
                          $(this).text("已发货")
                      } else if ($(this).text() == 4) {
                          $(this).text("已完成")
                      }
                  });
              }
              , height: 500
          });

          //点击表格右侧的查看订单详情和发货按钮
          table.on('tool(test)', function (obj) {
              var data = obj.data;
              if (obj.event === 'delever') {
                  layer.confirm('确认发货吗吗？', {
                      btn: ['确定','算了'], //按钮
                      title:"订单发货",
                      offset:"50px"
                  },function () {
                      layer.closeAll();
                      console.log('订单号是：'+data.orderId);
                      if (data.status!=2){
                          layer.msg('订单不是待发货状态，无法进行发货');
                          return false;
                      }
                      //将订单发货
                      $.ajax({
                          url:"/admin/delever",
                          data:{orderId:data.orderId},
                          type:'get',
                          success:function (data) {
                              if (data.code==1){
                                  layer.alert(data.message,{icon: 6},function (index) {
                                      // location.href="./toMemberinfo"
                                      location.reload();
                                  })
                              }else if(data.code==3){
                                  layer.msg(data.message);
                              }else {
                                  layer.msg(data.message,{icon: 5});
                              }
                          }
                      })
                  }, function(){
                  });

              }
              else if(obj.event === 'orderDetail'){
                  //查看订单详情
                  $.ajax({
                      url:"/admin/orderDetail",
                      data:{orderId:data.orderId},
                      type:'get',
                      success:function (data) {
                          if (data.code==1){
                              console.log("成功查询了吗")
                              console.log(data.data)
                                var orderItem=data.data;
                              console.log(orderItem.receiverName);
                              console.log(orderItem.totalPrice);
                              form.val('orderDetail-form', {
                                  "orderId": orderItem.orderId,
                                  "receiverName": orderItem.receiverName,
                                  "totalPrice": orderItem.totalPrice,
                                  "receiverPhone": orderItem.receiverPhone
                              });

                              layer.open({
                                  type: 1,
                                  title: '订单详情',
                                  skin: 'layui-layer-molv',
                                  area: ['800px'],
                                  content: $('#orderDetail-layer')
                              });
                          }else {
                              layer.msg(data.message,{icon: 5});
                          }
                      }
                  })


              }else if (obj.event === 'jiefeng') {
                  layer.confirm('确认将用户解封吗？', {
                      btn: ['确定','算了'], //按钮
                      title:"解封用户",
                      offset:"50px"
                  }, function(){
                      layer.closeAll();
                      $.ajax({
                          // url: basePath+'/admin/user/forbid/'+data.userid+"/1",
                          url: '/admin/user/forbid/'+data.userId+"/0",
                          data: "",
                          contentType: "application/json;charset=UTF-8", //发送数据的格式
                          type: "put",
                          dataType: "json", //回调
                          beforeSend: function () {
                              layer.load(1, { //icon支持传入0-2
                                  content: '请稍等...',
                                  success: function (layero) {
                                      layero.find('.layui-layer-content').css({
                                          'padding-top': '39px',
                                          'width': '60px'
                                      });
                                  }
                              });
                          },
                          complete: function () {
                              layer.closeAll('loading');
                          },
                          success: function (data) {
                              console.log(data)
                              if(data.code===2){
                                  layer.msg(data.message, {
                                      time: 1000,
                                      icon: 1,
                                      offset: '50px'
                                  }, function () {
                                      location.reload();
                                  });
                              }else {
                                  layer.msg(data.message, {
                                      time: 1000,
                                      icon: 2,
                                      offset: '50px'
                                  });
                              }
                          }
                      });
                  }, function(){
                  });
              }else if (obj.event === 'setadmin') {
                  layer.confirm('确认设置为管理员吗？', {
                      btn: ['确定','算了'], //按钮
                      title:"设置管理员",
                      offset:"50px"
                  }, function(){
                      layer.closeAll();
                      $.ajax({
                          url: basePath+'/admin/set/administrator/'+data.userid+"/2",
                          data: "",
                          contentType: "application/json;charset=UTF-8", //发送数据的格式
                          type: "put",
                          dataType: "json", //回调
                          beforeSend: function () {
                              layer.load(1, { //icon支持传入0-2
                                  content: '请稍等...',
                                  success: function (layero) {
                                      layero.find('.layui-layer-content').css({
                                          'padding-top': '39px',
                                          'width': '60px'
                                      });
                                  }
                              });
                          },
                          complete: function () {
                              layer.closeAll('loading');
                          },
                          success: function (data) {
                              console.log(data)
                              if(data.status===200){
                                  layer.msg(data.message, {
                                      time: 1000,
                                      icon: 1,
                                      offset: '50px'
                                  }, function () {
                                      location.reload();
                                  });
                              }else {
                                  layer.msg(data.message, {
                                      time: 1000,
                                      icon: 2,
                                      offset: '50px'
                                  });
                              }
                          }
                      });
                  }, function(){
                  });
              }
          });

          //点击表格上方的批量发货按钮
          table.on('toolbar(test)', function(obj){
              var checkStatus = table.checkStatus(obj.config.id)
                  ,data = checkStatus.data, //获取选中的数据
                  event = obj.event,
               orderIds=[];
              switch(obj.event){

                  case 'deleverMore':
                      if(data.length === 0){
                          layer.msg('请选择一行');
                      } else if(data.length >=1){
                          console.log(data)
                          console.log('看看是啥')
                          for (let i = 0; i <data.length ; i++) {
                                  // orderId=(orderId+data[i].orderId+",");
                              if (data[i].status!=2){
                                  layer.msg('有订单不是待发货状态，无法进行批量发货');
                                  return false;
                              }
                                  orderIds.push((data[i].orderId))

                          }
                          console.log('看看id数组');
                          console.log(orderIds);
                          // layer.msg(userId);前端拼接要删除的批量id为（id1，id2，id3……）格式
                          layer.alert('确认发货?：',function (index) {
                              $.ajax({
                                  url:"/admin/deleverMore",
                                  contentType: 'application/json',
                                  // data:{orderIds:orderIds},
                                  data:JSON.stringify(orderIds),
                                  type:'POST',
                                  success:function (data) {
                                      if (data.code==1){
                                          layer.alert(data.message,{icon: 6},function (index) {
                                              // location.href="./toMemberinfo"
                                              location.reload();
                                          })
                                      }
                                  }
                              })
                          })

                      }
                      break;
              };
          });


          //获取条件下拉框中的值
          form.on('select',function (data) {
              console.log(data.value);
              var status=data.value;
              table.reload('demo',{
                  method:'post',
                  url:'/admin/getOrderslistBycondition',
                  where:{
                      status:status,
                  }
                  ,page:{
                      curr:1
                  }
              })
              return false
          })



          $('#searchbyorder').on('click',function (data) {
              console.log("111111111")
              var orderId=$('#orderNumber').val();
              console.log(orderId)
              table.reload('demo',{
                  method:'post',
                  url:'/admin/searchbyorder',
                  where:{
                      orderId:orderId,
                  }
                  ,page:{
                      curr:1
                  }
              })
              return false
          })

          $('#searchAll').on('click',function (data) {
              console.log("111111111")
              // var username=$('#searchUserName').val();
              // console.log(username)
              table.reload('demo',{
                  method:'post',
                  url:'/admin/getAllOrderslist',
              })
              return false
          })

          //触发事件
          // table.on('toolbar(test)', function(obj){
          //     var checkStatus = table.checkStatus(obj.config.id)
          //         ,data = checkStatus.data, //获取选中的数据
          //         event = obj.event,
          //         userId="";
          //     switch(obj.event){
          //         case 'orderDetail':
          //             if(data.length === 0){
          //                 layer.msg('请选择一行');
          //             } else if(data.length > 1){
          //                 layer.msg('只能同时编辑一个');
          //                 // layer.alert(checkStatus.data.userName)
          //             } else {
          //                 //拼接请求地址
          //                 // x_admin_show("修改用户","/ssmhomework0419/selectById"+"?userId="+checkStatus.data[0].userId,700,500)
          //                 // layer.alert('编辑 [id]：'+ checkStatus.data[0].userId);
          //                 // 更新用户事件,回显数据
          //                 // 每次显示更新用户的表单前自动为表单填写该行的数据
          //                 form.val('update-user-form', {
          //                     "userId": checkStatus.data[0].userId,
          //                     "userName": checkStatus.data[0].userName,
          //                     "userPassword": checkStatus.data[0].userPassword,
          //                     "userSex": checkStatus.data[0].userSex,
          //                     "userPhone": checkStatus.data[0].userPhone
          //                 });
          //                 // 显示更新用户表单的弹出层
          //                 layer.open({
          //                     type: 1,
          //                     title: '更新用户',
          //                     skin: 'layui-layer-molv',
          //                     area: ['500px'],
          //                     content: $('#update-user-layer')
          //                 });
          //                 // 更新用户表单提交
          //                 form.on('submit(update-user-form-submit)', function(data) {
          //                     // ajax方式更新用户
          //                     var userId=checkStatus.data[0].userId;
          //                     $.ajax({
          //                         url: "./update",
          //                         type: "post",
          //                         data: JSON.stringify(data.field),
          //                         contentType: 'application/json',
          //                         dataType: 'json',
          //                         success: function(data) {
          //                             if (data.code==1) {
          //                                 layer.close(layer.index);
          //                                 // layer.msg(data.message);
          //                                 layer.alert(data.message,{icon: 6});
          //                                 table.reload('demo');
          //                             } else {
          //                                 layer.msg(data.message);
          //                             }
          //                         },
          //                         error: function() {
          //                             console.log("ajax error");
          //                         }
          //                     });
          //                     // 阻止表单跳转
          //                     return false;
          //                 });
          //
          //             }
          //             break;
          //         case 'delete':
          //             if(data.length === 0){
          //                 layer.msg('请选择一行');
          //             } else if(data.length >=1){
          //                 for (let i = 0; i <data.length ; i++) {
          //                     if (i!=data.length-1){
          //                         userId=(userId+data[i].userId+",");
          //                     }
          //                 }
          //                 userId=(userId+" " +data[data.length-1].userId);
          //                 // layer.msg(userId);前端拼接要删除的批量id为（id1，id2，id3……）格式
          //                 layer.alert('是否删除 以下[id]：'+userId,function (index) {
          //                     $.ajax({
          //                         url:"./deleteMore",
          //                         data:{ids:userId},
          //                         type:'get',
          //                         success:function (data) {
          //                             if (data.code==1){
          //                                 layer.alert(data.message,{icon: 6},function (index) {
          //                                     location.href="./toMemberinfo"
          //                                 })
          //                             }else {
          //                                 layer.msg(data.message,{icon: 5});
          //                             }
          //                         }
          //                     })
          //                 })
          //
          //             } else {
          //                 //实现批量删除后，可以不要以下代码
          //                 layer.alert('删除 [id]：'+ checkStatus.data[0].userId,function (index) {
          //                     var id=checkStatus.data[0].userId;
          //                     $.ajax({
          //                         url:"./delete",
          //                         data:{id:id},
          //                         type:'get',
          //                         success:function (data) {
          //                             if (data==1){
          //                                 location.href="./toMemberinfo"
          //                             }else {
          //                             }
          //                         }
          //                     })
          //                 });
          //             }
          //             break;
          //     };
          // });

      });

    </script>
  </body>





</html>